home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 2.toast / pc / sample code / quicktime / importers and exporters / std compression examples / example2.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-09-28  |  5.2 KB  |  172 lines

  1. /*
  2.     File:        Example2.c
  3.  
  4.     Contains:    Compression of PICT Files
  5.  
  6.                 The following sample code is similar to the previous example except
  7.                 that it requests files to compress until the user cancels and shows
  8.                 a slightly different use of the Standard Compression Dialog calls.
  9.                 
  10.                 This example is not a description of the "right" way to use these
  11.                 calls in an application.  It should be used for comparison with the
  12.                 other examples.  Example 3 is a better example of the "right" way to
  13.                 do things
  14. .
  15.     Written by:     
  16.  
  17.     Copyright:    Copyright © 1992-1999 by Apple Computer, Inc., All Rights Reserved.
  18.  
  19.                 You may incorporate this Apple sample source code into your program(s) without
  20.                 restriction. This Apple sample source code has been provided "AS IS" and the
  21.                 responsibility for its operation is yours. You are not permitted to redistribute
  22.                 this Apple sample source code as "Apple sample source code" after having made
  23.                 changes. If you're going to re-distribute the source, we require that you make
  24.                 it clear in the source that the code was descended from Apple sample source
  25.                 code, but that you've made changes.
  26.  
  27.     Change History (most recent first):
  28.                 8/17/1999    Karl Groethe    Updated for Metrowerks Codewarror Pro 2.1
  29.                 12/4/94        khs                changed the format of the file to the new look and feel
  30.  
  31. */
  32.  
  33. // INCLUDE FILES
  34. #include <menus.h>
  35. #include <fonts.h>
  36. #include <osevents.h>
  37. #include <components.h>
  38. #include <quicktimecomponents.h>
  39.  
  40.  
  41. // FUNCTION PROTOTYPES
  42. void Example2(void);
  43.  
  44.  
  45. // FUNCTIONS
  46. void Example2(void)
  47. {
  48.     ComponentResult result;
  49.     Point where;
  50.     ComponentInstance ci;
  51.     short sref;
  52.     SFTypeList typeList;
  53.     SFReply reply;
  54.  
  55.     //    Open the Standard Compression Dialog component.
  56.  
  57.     ci = OpenDefaultComponent(StandardCompressionType, StandardCompressionSubType);
  58.     if (ci)
  59.     {
  60.  
  61.         //    Tell SFGetFilePreview to center on the best monitor.
  62.  
  63.         where.h = where.v = -2;
  64.  
  65.         //    Show only 'PICT' files in the file list.
  66.  
  67.         typeList[0] = 'PICT';
  68.  
  69.         //    Keep asking the user for files until they cancel.
  70.  
  71.         reply.good = true;
  72.         while (reply.good)
  73.         {
  74.  
  75.             //    Ask user to select PICT file to be compressed.
  76.  
  77.             SFGetFilePreview(where, "\p", nil, 1, typeList, nil, &reply);
  78.             if (reply.good)
  79.             {
  80.  
  81.                 //    If they selected a file, open that file.
  82.  
  83.                 result = FSOpen(reply.fName, reply.vRefNum, &sref);
  84.                 if (!result)
  85.                 {
  86.  
  87.                     //    If the file opened successfully, set the picture file to
  88.                     //    be the test image shown in the dialog.  Passing nil for srcRect
  89.                     //    means use the entire image.  Passing 0 for testFlags means
  90.                     //    to use the default system method of displaying the test image
  91.                     //    which is currently a combination of cropping and scaling.
  92.  
  93.                     SCSetTestImagePictFile(ci, sref, nil, 0);
  94.  
  95.                     //    Because we may have already made default settings in a previous
  96.                     //    pass through this loop, we need to set defaults specific to the
  97.                     //    current picture file.  This is particularly important because
  98.                     //    defaults for the previous picture may include a color table
  99.                     //    that is not appropriate for the current picture.
  100.                     //
  101.                     //    There is a drawback to this approach.  If the user wants to use
  102.                     //    settings different from the defaults for several pictures, they
  103.                     //    have to change the settings each time the compression dialog comes
  104.                     //    up.  The next example will show a better way of handling this problem
  105.                     //    using the custom button.
  106.  
  107.                     result = SCDefaultPictFileSettings(ci, sref, false);
  108.                     if (!result)
  109.                     {
  110.  
  111.                         //    Now that we know there are current defaults settings, we must
  112.                         //    explicitly request settings from the user.  In the previous
  113.                         //    example, SCCompressPictureFile requested settings from the user
  114.                         //    for us because no default settings had been made.
  115.                         //
  116.                         //    Note that the result code returned could include scUserCancelled.
  117.  
  118.                         result = SCRequestImageSettings(ci);
  119.                         if (!result)
  120.                         {
  121.  
  122.                             //    Compress the picture file with the settings chosen by the user.
  123.                             //    The settings include any custom color table found in the source
  124.                             //    picture if still appropriate for the depth chosen by the user.
  125.                             //
  126.                             //    Again note that we are able to pass the source file ref for both the
  127.                             //    source and destination picture files.  In this case, the picture
  128.                             //    file will be compressed in place.  It would probably be better to
  129.                             //    ask the user for a name to save the compressed file as, rather than
  130.                             //    compressing it in place.
  131.  
  132.                             result = SCCompressPictureFile(ci, sref, sref);
  133.  
  134.                             //    Another implementation would be to clear out the current settings
  135.                             //    by calling SCSetInfo(ci,scSettingsStateType,nil) after calling
  136.                             //    SCSetTestImagePictfile.  We would then no longer need the calls
  137.                             //    to SCDefaultPictFileSettings and SCRequestImageSettings because
  138.                             //    SCCompressPictureFile would do that for us as it did in the first example.
  139.                         }
  140.                     }
  141.  
  142.                     //    Close the source picture file.
  143.  
  144.                     FSClose(sref);
  145.                 }
  146.             }
  147.         }
  148.  
  149.         //    Close the Standard Compression Dialog component.
  150.  
  151.         CloseComponent(ci);
  152.     }
  153. }
  154.  
  155.  
  156. // MAIN FUNCTION
  157. void main(void)
  158. {
  159.     InitGraf(&qd.thePort);
  160.     InitFonts();
  161.     FlushEvents(everyEvent, 0);
  162.     InitWindows();
  163.     InitMenus();
  164.     InitDialogs(nil);
  165.     InitCursor();
  166.     MaxApplZone();
  167.  
  168.     Example2();
  169. }
  170.  
  171.  
  172.